package com.haibei.adapter.bean;

import java.util.ArrayList;

import com.common.bean.IBeanInterface;
import com.common.uitl.StringUtils;
import com.common.uitl.Tool;
import com.haibei.net.NetInterface;

/**
 * @author zhanglei
 * @desc 资讯
 */
public class Article implements IBeanInterface {

	private static final long serialVersionUID = 5167615300955713219L;

	private String id;
	private String title;
	private String content;
	private String author;
	// 封面图片地址
	private String coverImg;
	private String categoryId;
	private String regionId;
	// 资讯来源
	private String origin;
	// 原文链接
	private String originalLink;
	// 发布时间
	private String publishTime;

	private String isOrigin;
	// 页面展示所需
	private ArticleCategory category;
	private ArticleRegion region;
	private ArrayList<ContentItem> contentList;
	private String shortContent;

	public Article() {
		contentList = new ArrayList<ContentItem>();
	}

	public String getShortContent() {
		return shortContent;
	}

	public void setShortContent(String shortContent) {
		this.shortContent = shortContent;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
		int shortContentLen = 30;
		if (!StringUtils.isEmpty(content)) {
//			String[] splite = content.split("<<img>>|<</img>>");
			String[] splite = content.split("<<img>>|<</img>>");
			for (String item : splite) {
				item = item.trim();
				item="    "+item;
				item= item.replace("<<br>>", "\n");
				item= item.replace("<<br/>>", "\n");
				if (!StringUtils.isEmpty(item)) {
					ContentItem i = new ContentItem(item);
					contentList.add(i);
					if (StringUtils.isEmpty(shortContent) && !Tool.isImgUrl(item) && item.length() > 4) {
						if (item.length() <= shortContentLen) {
							setShortContent(item.trim() + "...");
						} else {
							setShortContent(item.substring(0, shortContentLen - 1).trim() + "...");
						}
					}
				}

			}
		}
	}

	public ArrayList<ContentItem> getContentList() {
		return contentList;
	}

	public void setContentList(ArrayList<ContentItem> contentList) {
		this.contentList = contentList;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public String getCoverImg() {
		return coverImg;
	}

	public void setCoverImg(String coverImg) {
		this.coverImg = NetInterface.warpImgUrl(coverImg);
	}

	public String getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(String categoryId) {
		this.categoryId = categoryId;
	}

	public String getRegionId() {
		return regionId;
	}

	public void setRegionId(String regionId) {
		this.regionId = regionId;
	}

	public String getOrigin() {
		return origin;
	}

	public void setOrigin(String origin) {
		this.origin = origin;
	}

	public String getOriginalLink() {
		return originalLink;
	}

	public void setOriginalLink(String originalLink) {
		this.originalLink = originalLink;
	}

	public String getPublishTime() {
		return publishTime;
	}

	public void setPublishTime(String publishTime) {
		this.publishTime = publishTime;
	}

	public void setCategory(ArticleCategory category) {
		this.category = category;
	}

	public void setRegion(ArticleRegion region) {
		this.region = region;
	}

	public ArticleCategory getCategory() {
		return category;
	}

	public String getIsOrigin() {
		return isOrigin;
	}

	public void setIsOrigin(String isOrigin) {
		this.isOrigin = isOrigin;
	}

	public ArticleRegion getRegion() {
		return region;
	}

}
